<template>
  <div style="text-align: left">
    <div class="weui-cells__title">我的账户</div>
    <div class="weui-cells">
      <a class="weui-cell weui-cell_access" href="javascript:;">
        <div class="weui-cell__bd">
          <p>余额：{{account.yue}}</p>
        </div>
      </a>
      <a class="weui-cell weui-cell_access" href="javascript:;">
        <div class="weui-cell__bd">
          <p>可用额度：{{account.edu}}</p>
        </div>
      </a>
      <a class="weui-cell weui-cell_access" href="javascript:;">
        <div class="weui-cell__bd">
          <p>盈利：{{account.yingliYue}}</p>
        </div>
        <div class="weui-cell__ft" v-on:click="tiXianYingLi()">提现</div>
      </a>
      <a class="weui-cell weui-cell_access" href="javascript:;">
        <div class="weui-cell__bd">
          <p>游戏次数：{{parseInt(account.jifenYue*10)}} </p>
        </div>
      </a>
      <!--<a class="weui-cell weui-cell_access" href="javascript:;">
        <div class="weui-cell__bd">
          <p>积分：{{account.jifenYue}} <span class="weui-cells__title">1积分=1元</span></p>
        </div>
        <div class="weui-cell__ft" v-on:click="tiXianJifen()">提现</div>
      </a>-->
      <a class="weui-cell weui-cell_access" href="javascript:;">
        <div class="weui-cell__bd">
          <p>提现支付宝：{{account.zhifubao}}</p>
        </div>
        <div class="weui-cell__ft" v-on:click="inputZhifubao=true;" >{{account.zhifubao==''||account.zhifubao==null ? '绑定' : '修改'}}</div>
      </a>
      <div class="weui-cell weui-cell_vcode" v-show="inputZhifubao" >
        <div class="weui-cell__hd">
          <label class="weui-label">绑定支付宝</label>
        </div>
        <div class="weui-cell__bd">
          <input class="weui-input"  placeholder="请输入支付宝" v-model="account.zhifubao">
        </div>
        <div class="weui-cell__ft">
          <button class="weui-vcode-btn" v-on:click="bindingZhifubao()" > 确 定 </button>
          <button class="weui-vcode-btn" v-on:click="inputZhifubao=false;" > 取 消 </button>
        </div>
      </div>
    </div>
    <div style="padding: 10px;">
      <a href="javascript:;" v-on:click="applyYue()" class="weui-btn weui-btn_primary">申请余额</a>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Account',
  data () {
    return {
      account: {},
      inputZhifubao: false
    }
  },
  created () {
      document.title = "我的账户";
      this.getAccount()
  },
  methods: {
      getAccount: function () {
          this.$http.post('account/getAccount', {}).then(function (response) {
              this.account = response.data.data.account
          })
      },
      applyYue: function () {
          this.$http.post('account/applyYue', {}).then(function (response) {
              if(response.data.flag){
                  this.account = response.data.data.account
              }else{
                  this.showTips('申请失败，原因：'+response.data.msg,2000)
              }
          })
      },
      showTips: function (content,millisecond) {
          window.parent.document.getElementById('tips').style.display='';
          window.parent.document.getElementById('tipsContent').innerHTML=content;
          setTimeout(function () {
              window.parent.document.getElementById('tips').style.display='none';
          }, millisecond);
      },
      bindingZhifubao: function () {
          this.$http.post('account/bindingZhifubao?zhifubao='+this.account.zhifubao,{}).then(function (response) {
              if(response.data.flag){
                  this.showTips(response.data.msg,3000)
                  this.inputZhifubao = false
              }else{
                  this.showTips('绑定失败，原因：'+response.data.msg,2000)
              }
          })
      },
      tiXianJifen: function () {
          if(this.account.zhifubao==''||this.account.zhifubao==null ){
              this.showTips('请先绑定提现支付宝账号',2000)
              return false;
          }
          if(this.account.jifenYue>10){
              this.$http.post('account/tiXianJifen?amount='+this.account.jifenYue,{}).then(function (response) {
                  if(response.data.flag){
                      this.showTips(response.data.msg,3000)
                  }else{
                      this.showTips('提现失败，原因：'+response.data.msg,2000)
                  }
              })
          }else{
              this.showTips('积分大于10才可提现',2000)
          }
      },
      tiXianYingLi: function () {
          this.showTips('盈利大于10000才可提现',2000)
      }
  }
}
</script>
<style>

</style>
